<!doctype html>
<html class="no-js" lang="en, zh-CN" data-content_root="../">
  <head><meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width,initial-scale=1"/>
    <meta name="color-scheme" content="light dark"><meta name="generator" content="Docutils 0.19: https://docutils.sourceforge.io/" />
<link rel="index" title="Index" href="../genindex.html" /><link rel="search" title="Search" href="../search.html" /><link rel="next" title="Javet Performance" href="performance.html" /><link rel="prev" title="Test Javet" href="test.html" />

    <link rel="shortcut icon" href="../_static/logo.ico"/><!-- Generated with Sphinx 7.2.6 and Furo 2023.09.10 -->
        <title>Javet Design - Javet 3.0.0 documentation</title>
      <link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=a746c00c" />
    <link rel="stylesheet" type="text/css" href="../_static/styles/furo.css?v=135e06be" />
    <link rel="stylesheet" type="text/css" href="../_static/tabs.css?v=4c969af8" />
    <link rel="stylesheet" type="text/css" href="../_static/styles/furo-extensions.css?v=36a5483c" />
    <link rel="stylesheet" type="text/css" href="../_static/css/custom.css?v=c2631171" />
    
    


<style>
  body {
    --color-code-background: #f8f8f8;
  --color-code-foreground: black;
  
  }
  @media not print {
    body[data-theme="dark"] {
      --color-code-background: #202020;
  --color-code-foreground: #d0d0d0;
  
    }
    @media (prefers-color-scheme: dark) {
      body:not([data-theme="light"]) {
        --color-code-background: #202020;
  --color-code-foreground: #d0d0d0;
  
      }
    }
  }
</style></head>
  <body>
    
    <script>
      document.body.dataset.theme = localStorage.getItem("theme") || "auto";
    </script>
    

<svg xmlns="http://www.w3.org/2000/svg" style="display: none;">
  <symbol id="svg-toc" viewBox="0 0 24 24">
    <title>Contents</title>
    <svg stroke="currentColor" fill="currentColor" stroke-width="0" viewBox="0 0 1024 1024">
      <path d="M408 442h480c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8H408c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8zm-8 204c0 4.4 3.6 8 8 8h480c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8H408c-4.4 0-8 3.6-8 8v56zm504-486H120c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h784c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8zm0 632H120c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h784c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8zM115.4 518.9L271.7 642c5.8 4.6 14.4.5 14.4-6.9V388.9c0-7.4-8.5-11.5-14.4-6.9L115.4 505.1a8.74 8.74 0 0 0 0 13.8z"/>
    </svg>
  </symbol>
  <symbol id="svg-menu" viewBox="0 0 24 24">
    <title>Menu</title>
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor"
      stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather-menu">
      <line x1="3" y1="12" x2="21" y2="12"></line>
      <line x1="3" y1="6" x2="21" y2="6"></line>
      <line x1="3" y1="18" x2="21" y2="18"></line>
    </svg>
  </symbol>
  <symbol id="svg-arrow-right" viewBox="0 0 24 24">
    <title>Expand</title>
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor"
      stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather-chevron-right">
      <polyline points="9 18 15 12 9 6"></polyline>
    </svg>
  </symbol>
  <symbol id="svg-sun" viewBox="0 0 24 24">
    <title>Light mode</title>
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor"
      stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" class="feather-sun">
      <circle cx="12" cy="12" r="5"></circle>
      <line x1="12" y1="1" x2="12" y2="3"></line>
      <line x1="12" y1="21" x2="12" y2="23"></line>
      <line x1="4.22" y1="4.22" x2="5.64" y2="5.64"></line>
      <line x1="18.36" y1="18.36" x2="19.78" y2="19.78"></line>
      <line x1="1" y1="12" x2="3" y2="12"></line>
      <line x1="21" y1="12" x2="23" y2="12"></line>
      <line x1="4.22" y1="19.78" x2="5.64" y2="18.36"></line>
      <line x1="18.36" y1="5.64" x2="19.78" y2="4.22"></line>
    </svg>
  </symbol>
  <symbol id="svg-moon" viewBox="0 0 24 24">
    <title>Dark mode</title>
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor"
      stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" class="icon-tabler-moon">
      <path stroke="none" d="M0 0h24v24H0z" fill="none" />
      <path d="M12 3c.132 0 .263 0 .393 0a7.5 7.5 0 0 0 7.92 12.446a9 9 0 1 1 -8.313 -12.454z" />
    </svg>
  </symbol>
  <symbol id="svg-sun-half" viewBox="0 0 24 24">
    <title>Auto light/dark mode</title>
    <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor"
      stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" class="icon-tabler-shadow">
      <path stroke="none" d="M0 0h24v24H0z" fill="none"/>
      <circle cx="12" cy="12" r="9" />
      <path d="M13 12h5" />
      <path d="M13 15h4" />
      <path d="M13 18h1" />
      <path d="M13 9h4" />
      <path d="M13 6h1" />
    </svg>
  </symbol>
</svg>

<input type="checkbox" class="sidebar-toggle" name="__navigation" id="__navigation">
<input type="checkbox" class="sidebar-toggle" name="__toc" id="__toc">
<label class="overlay sidebar-overlay" for="__navigation">
  <div class="visually-hidden">Hide navigation sidebar</div>
</label>
<label class="overlay toc-overlay" for="__toc">
  <div class="visually-hidden">Hide table of contents sidebar</div>
</label>



<div class="page">
  <header class="mobile-header">
    <div class="header-left">
      <label class="nav-overlay-icon" for="__navigation">
        <div class="visually-hidden">Toggle site navigation sidebar</div>
        <i class="icon"><svg><use href="#svg-menu"></use></svg></i>
      </label>
    </div>
    <div class="header-center">
      <a href="../index.html"><div class="brand">Javet 3.0.0 documentation</div></a>
    </div>
    <div class="header-right">
      <div class="theme-toggle-container theme-toggle-header">
        <button class="theme-toggle">
          <div class="visually-hidden">Toggle Light / Dark / Auto color theme</div>
          <svg class="theme-icon-when-auto"><use href="#svg-sun-half"></use></svg>
          <svg class="theme-icon-when-dark"><use href="#svg-moon"></use></svg>
          <svg class="theme-icon-when-light"><use href="#svg-sun"></use></svg>
        </button>
      </div>
      <label class="toc-overlay-icon toc-header-icon" for="__toc">
        <div class="visually-hidden">Toggle table of contents sidebar</div>
        <i class="icon"><svg><use href="#svg-toc"></use></svg></i>
      </label>
    </div>
  </header>
  <aside class="sidebar-drawer">
    <div class="sidebar-container">
      
      <div class="sidebar-sticky"><a class="sidebar-brand" href="../index.html">
  
  <div class="sidebar-logo-container">
    <img class="sidebar-logo" src="../_static/logo.png" alt="Logo"/>
  </div>
  
  <span class="sidebar-brand-text">Javet 3.0.0 documentation</span>
  
</a><form class="sidebar-search-container" method="get" action="../search.html" role="search">
  <input class="sidebar-search" placeholder="Search" name="q" aria-label="Search">
  <input type="hidden" name="check_keywords" value="yes">
  <input type="hidden" name="area" value="default">
</form>
<div id="searchbox"></div><div class="sidebar-scroll"><div class="sidebar-tree">
  <ul class="current">
<li class="toctree-l1 has-children"><a class="reference internal" href="../tutorial/index.html">Tutorial</a><input class="toctree-checkbox" id="toctree-checkbox-1" name="toctree-checkbox-1" role="switch" type="checkbox"/><label for="toctree-checkbox-1"><div class="visually-hidden">Toggle navigation of Tutorial</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul>
<li class="toctree-l2 has-children"><a class="reference internal" href="../tutorial/basic/index.html">Basic</a><input class="toctree-checkbox" id="toctree-checkbox-2" name="toctree-checkbox-2" role="switch" type="checkbox"/><label for="toctree-checkbox-2"><div class="visually-hidden">Toggle navigation of Basic</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul>
<li class="toctree-l3"><a class="reference internal" href="../tutorial/basic/installation.html">Installation</a></li>
<li class="toctree-l3"><a class="reference internal" href="../tutorial/basic/hello_javet.html">Hello Javet</a></li>
<li class="toctree-l3"><a class="reference internal" href="../tutorial/basic/javet_shell.html">Javet Shell</a></li>
<li class="toctree-l3"><a class="reference internal" href="../tutorial/basic/interception.html">Interception</a></li>
<li class="toctree-l3"><a class="reference internal" href="../tutorial/basic/engine_pool.html">Javet Engine Pool</a></li>
<li class="toctree-l3"><a class="reference internal" href="../tutorial/basic/node_js_mode_and_v8_mode.html">Node.js Mode and V8 Mode</a></li>
<li class="toctree-l3"><a class="reference internal" href="../tutorial/basic/spring_integration.html">Spring Integration</a></li>
<li class="toctree-l3"><a class="reference internal" href="../tutorial/basic/polyfill.html">Polyfill</a></li>
</ul>
</li>
<li class="toctree-l2 has-children"><a class="reference internal" href="../tutorial/advanced/index.html">Advanced</a><input class="toctree-checkbox" id="toctree-checkbox-3" name="toctree-checkbox-3" role="switch" type="checkbox"/><label for="toctree-checkbox-3"><div class="visually-hidden">Toggle navigation of Advanced</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul>
<li class="toctree-l3"><a class="reference internal" href="../tutorial/advanced/interact_with_node_js.html">Interact with Node.js</a></li>
<li class="toctree-l3"><a class="reference internal" href="../tutorial/advanced/object_converter.html">Object Converter</a></li>
<li class="toctree-l3"><a class="reference internal" href="../tutorial/advanced/java_and_javascript_interop.html">Java and JavaScript Interop</a></li>
<li class="toctree-l3"><a class="reference internal" href="../tutorial/advanced/expose_json_node_in_v8.html">Expose JsonNode in V8</a></li>
</ul>
</li>
<li class="toctree-l2 has-children"><a class="reference internal" href="../tutorial/migration_guides/index.html">Migration Guides</a><input class="toctree-checkbox" id="toctree-checkbox-4" name="toctree-checkbox-4" role="switch" type="checkbox"/><label for="toctree-checkbox-4"><div class="visually-hidden">Toggle navigation of Migration Guides</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul>
<li class="toctree-l3"><a class="reference internal" href="../tutorial/migration_guides/migrate_from_j2v8.html">Migrate from J2V8</a></li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l1 has-children"><a class="reference internal" href="../reference/index.html">Reference</a><input class="toctree-checkbox" id="toctree-checkbox-5" name="toctree-checkbox-5" role="switch" type="checkbox"/><label for="toctree-checkbox-5"><div class="visually-hidden">Toggle navigation of Reference</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul>
<li class="toctree-l2"><a class="reference internal" href="../reference/javadoc/index.html">API Reference</a></li>
<li class="toctree-l2 has-children"><a class="reference internal" href="../reference/v8_values/index.html">V8 Values</a><input class="toctree-checkbox" id="toctree-checkbox-6" name="toctree-checkbox-6" role="switch" type="checkbox"/><label for="toctree-checkbox-6"><div class="visually-hidden">Toggle navigation of V8 Values</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul>
<li class="toctree-l3"><a class="reference internal" href="../reference/v8_values/v8_collection.html">V8 Collection</a></li>
<li class="toctree-l3"><a class="reference internal" href="../reference/v8_values/v8_function.html">V8 Function</a></li>
<li class="toctree-l3"><a class="reference internal" href="../reference/v8_values/v8_promise.html">V8 Promise</a></li>
</ul>
</li>
<li class="toctree-l2 has-children"><a class="reference internal" href="../reference/converters/index.html">Converters</a><input class="toctree-checkbox" id="toctree-checkbox-7" name="toctree-checkbox-7" role="switch" type="checkbox"/><label for="toctree-checkbox-7"><div class="visually-hidden">Toggle navigation of Converters</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul>
<li class="toctree-l3"><a class="reference internal" href="../reference/converters/primitive_converter.html">Primitive Converter</a></li>
<li class="toctree-l3"><a class="reference internal" href="../reference/converters/object_converter.html">Object Converter</a></li>
<li class="toctree-l3"><a class="reference internal" href="../reference/converters/proxy_converter.html">Proxy Converter</a></li>
<li class="toctree-l3"><a class="reference internal" href="../reference/converters/bridge_converter.html">Bridge Converter</a></li>
<li class="toctree-l3"><a class="reference internal" href="../reference/converters/custom_converter.html">Custom Converter</a></li>
</ul>
</li>
<li class="toctree-l2 has-children"><a class="reference internal" href="../reference/resource_management/index.html">Resource Management</a><input class="toctree-checkbox" id="toctree-checkbox-8" name="toctree-checkbox-8" role="switch" type="checkbox"/><label for="toctree-checkbox-8"><div class="visually-hidden">Toggle navigation of Resource Management</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul>
<li class="toctree-l3"><a class="reference internal" href="../reference/resource_management/load_and_unload.html">Load and Unload</a></li>
<li class="toctree-l3"><a class="reference internal" href="../reference/resource_management/lock.html">Know the Lock</a></li>
<li class="toctree-l3"><a class="reference internal" href="../reference/resource_management/memory_management.html">Memory Management</a></li>
<li class="toctree-l3"><a class="reference internal" href="../reference/resource_management/modularization.html">Modularization</a></li>
<li class="toctree-l3"><a class="reference internal" href="../reference/resource_management/performance.html">Javet Performance</a></li>
</ul>
</li>
<li class="toctree-l2 has-children"><a class="reference internal" href="../reference/troubleshooting/index.html">Troubleshooting</a><input class="toctree-checkbox" id="toctree-checkbox-9" name="toctree-checkbox-9" role="switch" type="checkbox"/><label for="toctree-checkbox-9"><div class="visually-hidden">Toggle navigation of Troubleshooting</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul>
<li class="toctree-l3"><a class="reference internal" href="../reference/troubleshooting/error_codes.html">Error Codes</a></li>
<li class="toctree-l3"><a class="reference internal" href="../reference/troubleshooting/logging.html">Logging</a></li>
<li class="toctree-l3"><a class="reference internal" href="../reference/troubleshooting/termination.html">Termination</a></li>
</ul>
</li>
<li class="toctree-l2 has-children"><a class="reference internal" href="../reference/tips/index.html">Tips</a><input class="toctree-checkbox" id="toctree-checkbox-10" name="toctree-checkbox-10" role="switch" type="checkbox"/><label for="toctree-checkbox-10"><div class="visually-hidden">Toggle navigation of Tips</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul>
<li class="toctree-l3"><a class="reference internal" href="../reference/tips/best_practices.html">Best Practices</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="../reference/todo_list.html">TODO List</a></li>
</ul>
</li>
<li class="toctree-l1 has-children"><a class="reference internal" href="../release_notes/index.html">Release Notes</a><input class="toctree-checkbox" id="toctree-checkbox-11" name="toctree-checkbox-11" role="switch" type="checkbox"/><label for="toctree-checkbox-11"><div class="visually-hidden">Toggle navigation of Release Notes</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul>
<li class="toctree-l2"><a class="reference internal" href="../release_notes/release_notes_3_0.html">Release Notes 3.0.x</a></li>
</ul>
</li>
<li class="toctree-l1 has-children"><a class="reference internal" href="../faq/index.html">FAQ</a><input class="toctree-checkbox" id="toctree-checkbox-12" name="toctree-checkbox-12" role="switch" type="checkbox"/><label for="toctree-checkbox-12"><div class="visually-hidden">Toggle navigation of FAQ</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul>
<li class="toctree-l2 has-children"><a class="reference internal" href="../faq/background/index.html">Background</a><input class="toctree-checkbox" id="toctree-checkbox-13" name="toctree-checkbox-13" role="switch" type="checkbox"/><label for="toctree-checkbox-13"><div class="visually-hidden">Toggle navigation of Background</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul>
<li class="toctree-l3"><a class="reference internal" href="../faq/background/history_with_j2v8.html">History with J2V8</a></li>
<li class="toctree-l3"><a class="reference internal" href="../faq/background/what_is_the_motivation.html">What is the Motivation?</a></li>
</ul>
</li>
<li class="toctree-l2 has-children"><a class="reference internal" href="../faq/development/index.html">Development</a><input class="toctree-checkbox" id="toctree-checkbox-14" name="toctree-checkbox-14" role="switch" type="checkbox"/><label for="toctree-checkbox-14"><div class="visually-hidden">Toggle navigation of Development</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul>
<li class="toctree-l3"><a class="reference internal" href="../faq/development/how_to_think_in_javet.html">How to Think in Javet?</a></li>
<li class="toctree-l3"><a class="reference internal" href="../faq/development/where_are_es6_api_in_v8_mode.html">Where are ES6 API in V8 Mode?</a></li>
<li class="toctree-l3"><a class="reference internal" href="../faq/development/where_are_the_examples.html">Where are the Examples?</a></li>
<li class="toctree-l3"><a class="reference internal" href="../faq/development/why_is_the_inspector_disabled_in_node_js_mode.html">Why is the Inspector Disabled in Node.js Mode?</a></li>
</ul>
</li>
<li class="toctree-l2 has-children"><a class="reference internal" href="../faq/environment/index.html">Environment</a><input class="toctree-checkbox" id="toctree-checkbox-15" name="toctree-checkbox-15" role="switch" type="checkbox"/><label for="toctree-checkbox-15"><div class="visually-hidden">Toggle navigation of Environment</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul>
<li class="toctree-l3"><a class="reference internal" href="../faq/environment/can_javet_support_legacy_linux.html">Can Javet Support Legacy Linux?</a></li>
</ul>
</li>
<li class="toctree-l2 has-children"><a class="reference internal" href="../faq/troubleshooting/index.html">Troubleshooting</a><input class="toctree-checkbox" id="toctree-checkbox-16" name="toctree-checkbox-16" role="switch" type="checkbox"/><label for="toctree-checkbox-16"><div class="visually-hidden">Toggle navigation of Troubleshooting</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul>
<li class="toctree-l3"><a class="reference internal" href="../faq/troubleshooting/a_dynamic_link_library_dll_initialization_routine_failed.html">A dynamic link library (DLL) initialization routine failed</a></li>
<li class="toctree-l3"><a class="reference internal" href="../faq/troubleshooting/can_i18n_be_supported.html">Can i18n be Supported?</a></li>
<li class="toctree-l3"><a class="reference internal" href="../faq/troubleshooting/can_i_debug_javet_in_chrome_dev_tools.html">Can I Debug Javet in Chrome DevTools?</a></li>
<li class="toctree-l3"><a class="reference internal" href="../faq/troubleshooting/why_node_js_crashes_when_being_closed.html">Why Node.js Crashes When being Closed?</a></li>
</ul>
</li>
</ul>
</li>
<li class="toctree-l1 current has-children"><a class="reference internal" href="index.html">Development</a><input checked="" class="toctree-checkbox" id="toctree-checkbox-17" name="toctree-checkbox-17" role="switch" type="checkbox"/><label for="toctree-checkbox-17"><div class="visually-hidden">Toggle navigation of Development</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="tools.html">Development Tools</a></li>
<li class="toctree-l2 has-children"><a class="reference internal" href="build.html">Build Javet</a><input class="toctree-checkbox" id="toctree-checkbox-18" name="toctree-checkbox-18" role="switch" type="checkbox"/><label for="toctree-checkbox-18"><div class="visually-hidden">Toggle navigation of Build Javet</div><i class="icon"><svg><use href="#svg-arrow-right"></use></svg></i></label><ul>
<li class="toctree-l3"><a class="reference internal" href="build_javet_with_docker.html">Build Javet with Docker</a></li>
<li class="toctree-l3"><a class="reference internal" href="build_javet_from_scratch.html">Build Javet from Scratch</a></li>
</ul>
</li>
<li class="toctree-l2"><a class="reference internal" href="test.html">Test Javet</a></li>
<li class="toctree-l2 current current-page"><a class="current reference internal" href="#">Javet Design</a></li>
<li class="toctree-l2"><a class="reference internal" href="performance.html">Javet Performance</a></li>
<li class="toctree-l2"><a class="reference internal" href="debug_with_chrome_developer_tools.html">Debug with Chrome Developer Tools</a></li>
</ul>
</li>
</ul>

</div>
</div>

      </div>
      
    </div>
  </aside>
  <div class="main">
    <div class="content">
      <div class="article-container">
        <a href="#" class="back-to-top muted-link">
          <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">
            <path d="M13 20h-2V8l-5.5 5.5-1.42-1.42L12 4.16l7.92 7.92-1.42 1.42L13 8v12z"></path>
          </svg>
          <span>Back to top</span>
        </a>
        <div class="content-icon-container">
          
<div class="theme-toggle-container theme-toggle-content">
            <button class="theme-toggle">
              <div class="visually-hidden">Toggle Light / Dark / Auto color theme</div>
              <svg class="theme-icon-when-auto"><use href="#svg-sun-half"></use></svg>
              <svg class="theme-icon-when-dark"><use href="#svg-moon"></use></svg>
              <svg class="theme-icon-when-light"><use href="#svg-sun"></use></svg>
            </button>
          </div>
          <label class="toc-overlay-icon toc-content-icon" for="__toc">
            <div class="visually-hidden">Toggle table of contents sidebar</div>
            <i class="icon"><svg><use href="#svg-toc"></use></svg></i>
          </label>
        </div>
        <article role="main">
          <section id="javet-design">
<h1>Javet Design<a class="headerlink" href="#javet-design" title="Link to this heading">#</a></h1>
<section id="architecture">
<h2>Architecture<a class="headerlink" href="#architecture" title="Link to this heading">#</a></h2>
<img alt="Javet Architecture" src="../_images/javet_architecture.png" />
<section id="primitive-and-reference-types-in-javet">
<h3>Primitive and Reference Types in Javet<a class="headerlink" href="#primitive-and-reference-types-in-javet" title="Link to this heading">#</a></h3>
<p>There is a vague boundary between V8 primitive and reference types. In Javet, the definition of primitive is a mixture of both V8 and Java primitive types as a trade-off in design.</p>
<div class="table-wrapper docutils container">
<table class="docutils align-default">
<thead>
<tr class="row-odd"><th class="head"><p>Feature</p></th>
<th class="head"><p>Primitive</p></th>
<th class="head"><p>Reference</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p>Interception</p></td>
<td><p>No</p></td>
<td><p>Yes</p></td>
</tr>
<tr class="row-odd"><td><p>Memory Copy</p></td>
<td><p>Copy by Value</p></td>
<td><p>Copy by Reference</p></td>
</tr>
<tr class="row-even"><td><p>Resource Leak</p></td>
<td><p>Not Possible</p></td>
<td><p>Possible</p></td>
</tr>
<tr class="row-odd"><td><p>Set to Weak</p></td>
<td><p>No</p></td>
<td><p>Yes</p></td>
</tr>
</tbody>
</table>
</div>
<p>Reference typed objects keep memory footprint in V8 + JNI + JVM. All resource will be recycled when <code class="docutils literal notranslate"><span class="pre">close()</span></code> is called. That is quite an old school way of managing resource. Javet tries to hide that kind of tedious work from Java applications via try-with-resource.</p>
<p>Please refer to <a class="reference internal" href="../reference/tips/best_practices.html"><span class="doc">Best Practices</span></a> for details.</p>
</section>
</section>
<section id="node-js-mode-vs-v8-mode">
<h2>Node.js Mode vs. V8 Mode<a class="headerlink" href="#node-js-mode-vs-v8-mode" title="Link to this heading">#</a></h2>
<p>Javet supports both Node.js mode and V8 mode both of which can co-exist in one JVM. In other words, they can run side by side and don't interfere with each other.</p>
<img alt="Javet Modes" src="../_images/javet_modes.png" />
<p>As the diagram shows, both Node.js and V8 are lazy loaded in dedicated custom classloaders. Detailed comparisons are as following.</p>
<div class="table-wrapper docutils container">
<table class="docutils align-default">
<thead>
<tr class="row-odd"><th class="head"><p>Feature</p></th>
<th class="head"><p>Node.js Mode</p></th>
<th class="head"><p>V8 Mode</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p>Lazy Loadable</p></td>
<td><p><strong>Yes</strong></p></td>
<td><p><strong>Yes</strong></p></td>
</tr>
<tr class="row-odd"><td><p>Customization</p></td>
<td><p><strong>High</strong></p></td>
<td><p><strong>High</strong></p></td>
</tr>
<tr class="row-even"><td><p>Node.js Ecosystem</p></td>
<td><p><strong>Complete</strong></p></td>
<td><p>No</p></td>
</tr>
<tr class="row-odd"><td><p>Security</p></td>
<td><p>Low</p></td>
<td><p><strong>High</strong></p></td>
</tr>
<tr class="row-even"><td><p>Unload</p></td>
<td><p><strong>Yes</strong></p></td>
<td><p><strong>Yes</strong></p></td>
</tr>
<tr class="row-odd"><td><p>V8 Ecosystem</p></td>
<td><p><strong>Complete</strong></p></td>
<td><p><strong>Complete</strong></p></td>
</tr>
<tr class="row-even"><td><p>V8 Version</p></td>
<td><p>Low</p></td>
<td><p><strong>High</strong></p></td>
</tr>
</tbody>
</table>
</div>
<p>One of the beauties of Javet is all the features in V8 mode can be applied to Node.js mode. Here are some examples.</p>
<ul class="simple">
<li><p>Virtualization - All Node.js modules can be virtualized. E.g. <code class="docutils literal notranslate"><span class="pre">console</span></code>, <code class="docutils literal notranslate"><span class="pre">fs</span></code>, <code class="docutils literal notranslate"><span class="pre">HTTP</span></code>, <code class="docutils literal notranslate"><span class="pre">Net</span></code>, <code class="docutils literal notranslate"><span class="pre">OS</span></code>, etc.</p></li>
<li><p>Zero-copy - JVM can share the same byte buffer with Node.js and V8 to achieve zero-copy.</p></li>
<li><p>Multi-threading - Multiple Java threads can host multiple Node.js runtime instances with only one copy of V8 objects visible to those instances.</p></li>
<li><p>Beyond Node.js - Javet allows explicit <code class="docutils literal notranslate"><span class="pre">await()</span></code> so that applications can take more control over <code class="docutils literal notranslate"><span class="pre">async</span></code> execution.</p></li>
</ul>
</section>
<section id="module">
<h2>Module<a class="headerlink" href="#module" title="Link to this heading">#</a></h2>
<p>Executing all scripts in global context is not recommended when project size increases. Javet provides complete support to applications so that V8 runtime context is aligned with the way Node or Chrome does. That brings the module system.</p>
<p>Unfortunately, V8 has very limited support to the JS module system. However, that is not bad because V8 leaves all the possibilities to Javet. The typical challenges Javet faces are as following.</p>
<ul class="simple">
<li><p>Sync or Async</p></li>
<li><p>Module Location</p></li>
<li><p>Module Dependency</p></li>
</ul>
<section id="require-vs-import">
<h3>require() vs. import()<a class="headerlink" href="#require-vs-import" title="Link to this heading">#</a></h3>
<div class="table-wrapper docutils container">
<table class="docutils align-default">
<thead>
<tr class="row-odd"><th class="head"><p>Feature</p></th>
<th class="head"><p>Async</p></th>
<th class="head"><p>Original V8</p></th>
<th class="head"><p>Javet Node.js Mode</p></th>
<th class="head"><p>Javet V8 Mode</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">require()</span></code></p></td>
<td><p>No</p></td>
<td><p>No</p></td>
<td><p>Yes (Complete)</p></td>
<td><p>Yes (with an Interceptor)</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">import()</span></code></p></td>
<td><p>Yes</p></td>
<td><p>Yes (Partial)</p></td>
<td><p>Yes (Complete)</p></td>
<td><p>Yes (Complete)</p></td>
</tr>
</tbody>
</table>
</div>
</section>
<section id="module-virtualization">
<h3>Module Virtualization<a class="headerlink" href="#module-virtualization" title="Link to this heading">#</a></h3>
<p>Javet doesn't build <code class="docutils literal notranslate"><span class="pre">require()</span></code> in but allows applications to set an interceptor because Javet doesn't know how to locate the modules and doesn't want to know for security issues. So it's up to the applications to define their own ways of locating the modules.</p>
<p>Javet provides complete support to ES6 <code class="docutils literal notranslate"><span class="pre">import()</span></code> because certain work inside JNI has to be in place as V8 only partially supports <code class="docutils literal notranslate"><span class="pre">import()</span></code>. So, in Javet the module is kind of virtualized, in other words, the module is represented by an arbitrary string that can be interpreted by applications during runtime. E.g. <code class="docutils literal notranslate"><span class="pre">module.js</span></code> may come from a file, a URL, a string in memory or whatever. Javet stores the compiled and evaluated module in a map with that string as key, and feeds V8 that module when V8 looks it up by that string.</p>
<img alt="Javet Module System" src="../_images/javet_module_system.png" />
</section>
</section>
<section id="engine-pool">
<h2>Engine Pool<a class="headerlink" href="#engine-pool" title="Link to this heading">#</a></h2>
<img alt="Javet Engine Pool" src="../_images/javet_engine_pool.png" />
<section id="v8-isolate-and-context-in-javet">
<h3>V8 Isolate and Context in Javet<a class="headerlink" href="#v8-isolate-and-context-in-javet" title="Link to this heading">#</a></h3>
<p><a class="reference external" href="https://v8.dev/docs/embed">Getting started with embedding V8</a> is an excellent article that explains the concepts, design, insights of V8. In summary:</p>
<ul class="simple">
<li><p>An isolate is a VM instance with its own heap.</p></li>
<li><p>A context is an execution environment that allows separate, unrelated, JavaScript applications to run in a single instance of V8.</p></li>
</ul>
<p>In Javet, that model is simplified to 1 engine - 1 runtime - 1 isolate - 1 context. In V8Runtime, <code class="docutils literal notranslate"><span class="pre">resetIsolate()</span></code> and <code class="docutils literal notranslate"><span class="pre">resetContext()</span></code> are both exposed. It is recommended to always use <code class="docutils literal notranslate"><span class="pre">resetContext()</span></code> to get a brand new V8 context for the following reasons.</p>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">resetContext()</span></code> is a much cheaper operation with much better performance.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">resetContext()</span></code> is good enough in terms of getting a brand new V8 context.</p></li>
</ul>
</section>
<section id="javet-engine-pool">
<h3>Javet Engine Pool<a class="headerlink" href="#javet-engine-pool" title="Link to this heading">#</a></h3>
<p>Multiple Javet engines are managed by Javet Engine Pool which works almost the same way as a typical DB connection pool. Javet Engine Pool is thread-safe. However, Javet Engine is <strong>NOT</strong> thread-safe because it is designed to be single-threaded and lock free for the following reasons.</p>
<ul class="simple">
<li><p>V8 isolate and V8 context are single-threaded. Thread context violation results in V8 core dump immediately.</p></li>
<li><p>Javet Engine performs better without locks. Actually, Javet engine only validates current thread ID to minimize the performance overhead.</p></li>
</ul>
<p>Please refer to <a class="reference internal" href="../reference/tips/best_practices.html"><span class="doc">Best Practices</span></a> for details.</p>
</section>
</section>
<section id="interception">
<h2>Interception<a class="headerlink" href="#interception" title="Link to this heading">#</a></h2>
<p>Javet allows intercepting almost all V8 API so that JS code actually interacts with Java code behind the scene.</p>
<img alt="Javet Interception" src="../_images/javet_interception.png" />
<p>Sample code is available at <a class="reference internal" href="../reference/v8_values/v8_function.html"><span class="doc">V8 Function</span></a>.</p>
</section>
<section id="cross-platform">
<h2>Cross-platform<a class="headerlink" href="#cross-platform" title="Link to this heading">#</a></h2>
<p>Javet packages all the libraries in a single jar file and automatically loads corresponding library per OS and JS runtime.</p>
<img alt="Javet Cross-platform" src="../_images/javet_cross_platform.png" />
<ul class="simple">
<li><p>Javet calculates the library file name from OS and JS runtime.</p></li>
<li><p>Javet unpacks the library files from resource directory to <code class="docutils literal notranslate"><span class="pre">system_temporary_directory/javet/pid</span></code>.</p></li>
<li><p>Javet loads the library files using either default classloader or custom classloader.</p></li>
</ul>
<section id="multi-process-safety">
<h3>Multi-process Safety<a class="headerlink" href="#multi-process-safety" title="Link to this heading">#</a></h3>
<p>Javet is multi-process safe because it deploys the library files to <code class="docutils literal notranslate"><span class="pre">system_temporary_directory/javet/pid</span></code> to avoid race conditions during initialization. Also, Javet purges legacy libraries (at least 1 minute old) at the beginning of the initialization.</p>
</section>
</section>
<section id="memory-leak-detection">
<h2>Memory Leak Detection<a class="headerlink" href="#memory-leak-detection" title="Link to this heading">#</a></h2>
<p>Javet native library keeps track of every <code class="docutils literal notranslate"><span class="pre">new</span></code> and <code class="docutils literal notranslate"><span class="pre">delete</span></code> in <code class="docutils literal notranslate"><span class="pre">JavetNativeMonitor</span></code>. Javet every unit test case fetches the tracking data, compares the <code class="docutils literal notranslate"><span class="pre">new</span></code> and <code class="docutils literal notranslate"><span class="pre">delete</span></code> count to verify unmanaged objects are properly allocated and freed.</p>
<p>This feature is only turned on in debug version and there is zero performance overhead in release version.</p>
</section>
</section>

        </article>
      </div>
      <footer>
        
        <div class="related-pages">
          <a class="next-page" href="performance.html">
              <div class="page-info">
                <div class="context">
                  <span>Next</span>
                </div>
                <div class="title">Javet Performance</div>
              </div>
              <svg class="furo-related-icon"><use href="#svg-arrow-right"></use></svg>
            </a>
          <a class="prev-page" href="test.html">
              <svg class="furo-related-icon"><use href="#svg-arrow-right"></use></svg>
              <div class="page-info">
                <div class="context">
                  <span>Previous</span>
                </div>
                
                <div class="title">Test Javet</div>
                
              </div>
            </a>
        </div>
        <div class="bottom-of-page">
          <div class="left-details">
            <div class="copyright">
                Copyright &#169; 2021-2023. caoccao.com Sam Cao
            </div>
            Made with 
            <a href="https://github.com/pradyunsg/furo">Furo</a>
            
          </div>
          <div class="right-details">
            
          </div>
        </div>
        
      </footer>
    </div>
    <aside class="toc-drawer">
      
      
      <div class="toc-sticky toc-scroll">
        <div class="toc-title-container">
          <span class="toc-title">
            On this page
          </span>
        </div>
        <div class="toc-tree-container">
          <div class="toc-tree">
            <ul>
<li><a class="reference internal" href="#">Javet Design</a><ul>
<li><a class="reference internal" href="#architecture">Architecture</a><ul>
<li><a class="reference internal" href="#primitive-and-reference-types-in-javet">Primitive and Reference Types in Javet</a></li>
</ul>
</li>
<li><a class="reference internal" href="#node-js-mode-vs-v8-mode">Node.js Mode vs. V8 Mode</a></li>
<li><a class="reference internal" href="#module">Module</a><ul>
<li><a class="reference internal" href="#require-vs-import">require() vs. import()</a></li>
<li><a class="reference internal" href="#module-virtualization">Module Virtualization</a></li>
</ul>
</li>
<li><a class="reference internal" href="#engine-pool">Engine Pool</a><ul>
<li><a class="reference internal" href="#v8-isolate-and-context-in-javet">V8 Isolate and Context in Javet</a></li>
<li><a class="reference internal" href="#javet-engine-pool">Javet Engine Pool</a></li>
</ul>
</li>
<li><a class="reference internal" href="#interception">Interception</a></li>
<li><a class="reference internal" href="#cross-platform">Cross-platform</a><ul>
<li><a class="reference internal" href="#multi-process-safety">Multi-process Safety</a></li>
</ul>
</li>
<li><a class="reference internal" href="#memory-leak-detection">Memory Leak Detection</a></li>
</ul>
</li>
</ul>

          </div>
        </div>
      </div>
      
      
    </aside>
  </div>
</div><script src="../_static/documentation_options.js?v=5e0dd536"></script>
    <script src="../_static/doctools.js?v=888ff710"></script>
    <script src="../_static/sphinx_highlight.js?v=dc90522c"></script>
    <script src="../_static/scripts/furo.js?v=32e29ea5"></script>
    <script src="../_static/tabs.js?v=3ee01567"></script>
    </body>
</html>